import {
  createMemoryHistory,
  createRouter,
  createWebHashHistory,
} from 'vue-router';

console.log('TeldWebConfig', TeldWebConfig);
const router = createRouter({
  history: import.meta.env.SSR ? createMemoryHistory() : createWebHashHistory(),
  routes: [
    {
      path: '/:pathMatch(.*)*',
      name: 'notFound',
      redirect: '404',
    },
    {
      path: '/',
      name: 'home',
      redirect: 't-button',
      component: () => import('src/Layout'),
      meta: {
        // locale: 'a.b',
        // icon: 'icon-settings',
        // order: 3,
      },
      children: [
        {
          path: '404',
          name: '404',
          component: () => import('src/common/404.vue'),
          meta: {
            locale: 'a.b.c',
          },
        },
        ...Object.entries(
          import.meta.glob('src/views/*/index.(vue|jsx|js)'),
        ).map(([k, v], i, a) => {
          let p = `t-${k.split('/').at(-2)}`;
          return {
            path: p,
            name: p,
            component: v,
            meta: {},
          };
        }),
      ],
    },
  ],
  scrollBehavior() {
    return { top: 0 };
  },
});

export default router;
